using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class MyPhysicsManager : MonoBehaviour
{
    public static MyPhysicsManager instance;
    public Dictionary<int,Behavior> behaviors;
    private void Awake()
    {
        instance = this;
        behaviors = new();
        
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }
    public void PositionMove(GameObject gameObject,Vector3 dest,double delay)
    {
        var behavior = new Behavior(MyGameManager.instance.clockCount, delay);
        var start=gameObject.transform.position;
        behavior.doingThing = () =>
        {
            var x=Mathf.Lerp(start.x, dest.x, (float)((MyGameManager.instance.clockCount - behavior.startTime) / delay));
            
            gameObject.transform.position=new(x,0,0);
            Debug.Log(x+"isworking  "+ (MyGameManager.instance.clockCount - behavior.startTime)/delay);

        };
        this.behaviors.Add(behaviors.Count, behavior);
    }
    private void FixedUpdate()
    {
        List<int> removekey = new();
        foreach (var item in behaviors)
        {
            if (!item.Value.isDone)
            {
                item.Value.doing(MyGameManager.instance.clockCount);
            }
            else
            {
                removekey.Add(item.Key);
            }
            
        }
        foreach(int  key in removekey)
        {
            behaviors.Remove(key);
        }
       

    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
